package com.itrip.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itrip.entity.ItripComment;
import com.itrip.vo.comment.ItripCountCommentVO;
import com.itrip.vo.comment.ItripListCommentVO;
import com.itrip.vo.comment.ItripScoreCommentVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ItripCommentMapper extends BaseMapper<ItripComment>{
      @Select("select AVG(FacilitiesScore) as avgFacilitiesScore,AVG(HygieneScore)" +
              " as avgHygieneScore,AVG(PositionScore) as avgPositionScore,AVG(Score) " +
              "as avgScore,AVG(ServiceScore) as avgServiceScore " +
              "from itrip_comment i  \n" +
              "where hotelId=#{hotelId} GROUP By hotelId")
      public ItripScoreCommentVO itripScoreCommentVo(@Param("hotelId") Long hotelId);

      @Select("select count(isOk=0 or NULL )as improve,\n" +
              "count(isOk=1 or NULL) as isok,\n" +
              "count(isHavingImg=1 or null) as havingimg,\n" +
              "count(1) as allcomment\n" +
              "from itrip_comment where hotelId =#{cityId}")
      public ItripCountCommentVO itripCommentCount(@Param("cityId") Long cityId);

      @Select("<script>   SELECT c.id,c.content,c.creationDate,b.`name` as tripModeName,c.score,h.hotelLevel,c.isHavingImg,r.roomTitle,u.userCode,o.checkInDate FROM itrip_comment c\n" +
              "  LEFT JOIN itrip_label_dic b ON c.tripMode = b.id\t\n" +
              "  LEFT JOIN itrip_hotel h ON h.id = c.hotelId\n" +
              "  LEFT JOIN itrip_hotel_room r ON r.id = c.productId\n" +
              "  LEFT JOIN itrip_user u ON u.id = c.userId\n" +
              "  LEFT JOIN itrip_hotel_order o ON  c.orderId = o.id\n" +
              "  WHERE c.hotelId = #{hotelId}  " +
              "  <if test=\"isOk != -1\">AND c.isOk=#{isOk}</if> " +
              "  <if test=\"isHavingImg != -1\"> AND  c.isHavingImg = #{isHavingImg} </if>" +
              "   ORDER BY  c.creationDate DESC   limit #{pageNo} ,#{pageSize}" +
              "  </script>")
      public List<ItripListCommentVO> getListComment(@Param("hotelId") Long hotelId, @Param("isOk") Integer isOk, @Param("isHavingImg") Integer IsHavingImg
              , @Param("pageNo") Integer pageNo, @Param("pageSize") Integer pageSize);
      @Select("<script>" +
              " update itrip_hotel_order\n" +
              "    set orderStatus = 4,\n" +
              "    modifyDate = NOW()\n" +
              "    <if test=\"modifiedBy != null and modifiedBy!=''\">\n" +
              "        ,modifiedBy=#{modifiedBy}\n" +
              "    </if>\n" +
              "    where id=#{id}" +
              "</script>")
      public Integer updateHotelOrderStatus(@Param(value = "id")Long id, @Param(value = "modifiedBy")Long modifiedBy);
}
